home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Enigma Amiga CD
/
Listati
/
63-Marzo-Listato3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
6KB
|
178 lines
/****************************************************************************
* Listato 3 *
* Apre due finestre su uno schermo hires con porta condivisa; la prima e' *
* provvista di gadget di chiusura ed e' spostabile, la seconda e' una fines-*
* tra borderless; se viene selezionato il gadget di chiusura della prima fi-*
* nestra, il programma viene terminato; se si attiva il pulsante del mouse *
* sulla finestra borderless questa viene chiusa. *
* Questo programma inizia ad essere strutturato in maniera piu' ordinata; *
* osservate infatti che le operazioni di apertura vengono effettuate nella *
* procedura OpenAll(), mentre quelle di chiusura nella procedura CloseAll();*
* in quest'ultima viene sempre verificato che una cosa sia stata aperta *
* prima di chiuderla, in questa maniera tale procedura e' chiamata dalla *
* OpenAll() in caso di fallimento senza alcun pericolo, riducendo il codice *
* della OpenAll(). *
****************************************************************************/
#define INTUI_V36_NAMES_ONLY
/* inclusione file di supporto */
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <graphics/modeid.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/dos_protos.h>
struct Library *IntuitionBase = NULL; /* puntatore a intuition.library */
struct Screen *schermo = NULL; /* puntatore allo schermo */
struct Window *finestra1 = NULL; /* puntatore alla finestra 1 */
struct Window *finestra2 = NULL; /* puntatore alla finestra 2 */
struct MsgPort *IDCMPPort = NULL; /* puntatore alla porta IDCMP */
/* definizione prototipi di funzione */
void StripIntuiMessage(struct MsgPort *, struct Window *);
void CloseWindowSafely(struct Window *);
void WaitEvent(struct MsgPort *,struct IntuiMessage *);
void CloseAll(void);
void OpenAll(void);
void StripIntuiMessage(struct MsgPort *mp, struct Window *win)
{
struct IntuiMessage *msg;
struct Node *succ;
msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
if (msg != NULL)
{
while (succ = msg->ExecMessage.mn_Node.ln_Succ)
{
if (msg->IDCMPWindow == win)
{
Remove(msg);
ReplyMsg(msg);
}
msg = (struct IntuiMessage *)succ;
}
}
return;
}
void CloseWindowSafely(struct Window *win)
{
Forbid();
StripIntuiMessage(win->UserPort,win);
win->UserPort = NULL;
ModifyIDCMP(win,NULL);
Permit();
CloseWindow(win);
return;
}
void WaitEvent(struct MsgPort *porta,struct IntuiMessage *mess)
{
struct IntuiMessage *msg;
while ((msg = (struct IntuiMessage *)GetMsg(porta)) == NULL)
WaitPort(porta);
CopyMem(msg,mess,sizeof(struct IntuiMessage));
return;
}
/* procedura CloseAll() */
void CloseAll()
{
if (finestra2 != NULL) CloseWindowSafely(finestra2);
if (finestra1 != NULL) CloseWindowSafely(finestra1);
if (schermo != NULL) CloseScreen(schermo);
if (IDCMPPort != NULL) DeleteMsgPort(IDCMPPort);
if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
exit(0);
}
/* procedura OpenAll() */
void OpenAll()
{
UWORD Penne[] = { ~0 };
/* apriamo intuition.library, almeno version 36 */
if ((IntuitionBase = OpenLibrary("intuition.library",36L)) == NULL)
CloseAll();
/* apriamo una porta messaggi */
if ((IDCMPPort = CreateMsgPort()) == NULL)
CloseAll();
/* apriamo uno schermo con look 3D, hires, 2 bitplanes, e overscan OSCAN_TEXT */
if ((schermo = OpenScreenTags(NULL,SA_Pens,Penne,
SA_Depth,2,
SA_DisplayID,HIRES_KEY,
SA_Title,"Schermo esempio.",
SA_Type,CUSTOMSCREEN,
TAG_END)) == NULL)
CloseAll();
/* apre la prima finestra spostabile, con il gadget di chiusura */
if ((finestra1 = OpenWindowTags(NULL,WA_Left,10,
WA_Top,10,
WA_Width,350,
WA_Height,150,
WA_Title,"Finestra principale.",
WA_DragBar,TRUE,
WA_CloseGadget,TRUE,
WA_CustomScreen,(ULONG)schermo,
WA_IDCMP,NULL,
TAG_END)) == NULL)
CloseAll();
finestra1 -> UserPort = IDCMPPort;
ModifyIDCMP(finestra1,IDCMP_CLOSEWINDOW);
/* apre la seconda finestra senza bordi */
if ((finestra2 = OpenWindowTags(NULL,WA_Left,300,
WA_Top,100,
WA_Width,200,
WA_Height,100,
WA_Borderless,TRUE, /* senza bordi */
WA_CustomScreen,(ULONG)schermo,
WA_IDCMP,NULL,
TAG_END)) == NULL)
CloseAll();
finestra2 -> UserPort = IDCMPPort;
ModifyIDCMP(finestra2,IDCMP_MOUSEBUTTONS);
return;
}
void main()
{
struct IntuiMessage mm;
OpenAll(); /* apre tutte le strutture dati */
while(1)
{
WaitEvent(IDCMPPort,&mm); /* attende un evento */
if (mm.IDCMPWindow == finestra1)
{
if (mm.Class == IDCMP_CLOSEWINDOW) break;
/* se la finestra e' finestra1 e l'evento e' IDCMP_CLOSEWINDOW allora
interrompi il ciclo infinito ed esci */
}
else if (mm.IDCMPWindow == finestra2)
{
if (mm.Class == IDCMP_MOUSEBUTTONS)
{
CloseWindowSafely(finestra2);
finestra2 = NULL;
/* se la finestra e' finestra2 e l'evento e' IDCMP_MOUSEBUTTONS allora
chiudi la finestra e imposta finestra2 a NULL (in modo da non farla
richiudere in CloseAll()) */
}
}
}
CloseAll(); /* chiudi tutto ed esci */
}